package com.ess.user.service.role;

import com.ess.base.service.impl.BaseServiceImpl;
import com.ess.constants.Constants;
import com.ess.user.mapper.RoleMapper;
import com.ess.user.po.Role;
import com.github.abel533.entity.Example;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("roleService")
public class RoleServiceImpl extends BaseServiceImpl<Role> implements RoleService {

    @Autowired
    RoleMapper roleMapper;

    /**
     * 分页查询用户信息 可以设置排序，模糊查询
     *
     * @param page
     * @param rows
     * @param record
     * @return
     */
    public PageInfo<Role> queryPageListByCondition(int page, int rows, Role record) {
        PageHelper.startPage(page, rows);
        Example example = new Example(Role.class);
        example.setOrderByClause(Constants.ORDER_UPDATE_DESC);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("isDeleted", Constants.STRING_ZERO);
        if (StringUtils.isNotBlank(record.getRoleName())) {
            criteria.andLike("roleName", "%" + record.getRoleName() + "%");
        }
        if (StringUtils.isNotBlank(record.getStatus())) {
            criteria.andEqualTo("status", record.getStatus());
        }
        List<Role> list = super.mapper.selectByExample(example);
        return new PageInfo<Role>(list);
    }
}

